package com.qidian.mes.sys.controller;

import com.qidian.mes.log.annotation.OptionLogAnnotation;
import com.qidian.mes.log.emum.OptionType;
import com.qidian.mes.pojo.Dict;
import com.qidian.mes.pojo.DictData;
import com.qidian.mes.sys.service.DictDataService;
import com.qidian.mes.util.pojo.MESResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author 戴着假发的程序员
 * @Company 起点编程
 * @Time 2023/10/25 15:04
 * @Description
 */
@CrossOrigin
@RestController
@RequestMapping("/dictData")
public class DictDataController {
    @Autowired
    private DictDataService dictDataService;

    @GetMapping("/list")
    public MESResult list(Long dictId){
        System.out.println("***********************");
        System.out.println(dictId);
        return dictDataService.get(dictId);
    }
    /**
     *新增字典
     * @param dict
     * @return
     */
    @PostMapping("/save")
    @OptionLogAnnotation(optionModule = "sys",optionType = OptionType.INSERT)
    public MESResult save(@RequestBody DictData dictData) {
        return dictDataService.save(dictData);
    }

    /**
     * 根据id删除单个字典
     * @param dictId
     * @return
     */
    @DeleteMapping("/delete")
    public MESResult delete(Long dataId){
//        System.out.println("**-*-*-*-*-*-*-*-*-"+dictId);
        return dictDataService.delete(dataId);
    }

    /**
     * 批量删除字典
     * @param dictId
     * @return
     */
    @DeleteMapping("/deletes")
    public MESResult deletes(Long[] dataId){
        System.out.println("------------------------------------------");
        for (int i = 0; i < dataId.length; i++) {
            System.out.println(dataId[i]+",");
        }
        return dictDataService.deletes(dataId);
    }

    /**
     * 修改字典
     * @param dict
     * @return
     */
    @PutMapping("/update")
    public MESResult update(@RequestBody DictData dictData){
//        System.out.println("***-**-*-*-*-*-*"+dict);
        return dictDataService.update(dictData);
    }
    @RequestMapping("/selectById")
    public MESResult selectById(Long dataId){
        return dictDataService.getByDataId(dataId);
    }
}
